package me.shurufa.fragments;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.HashMap;
import java.util.Map;

import butterknife.ButterKnife;
import me.shurufa.R;
import me.shurufa.model.CatalogListResponse;
import me.shurufa.net.API;
import me.shurufa.net.RequestServerTask;
import me.shurufa.model.AddDigestBean;
import me.shurufa.utils.Constants;
import me.shurufa.utils.HttpUtil;

/**
 * 作者 : andy
 * 日期 : 16/3/9 10:31
 * 邮箱 : andyxialm@gmail.com
 * 描述 : 内容简介 Fragment
 */
public class SelectChapterFragment extends BaseFragment implements View.OnClickListener {

    private AddDigestBean mAddDigestBean;

    public static SelectChapterFragment create(AddDigestBean addDigestBean) {
        SelectChapterFragment fragment = new SelectChapterFragment();
        Bundle args = new Bundle();
        args.putSerializable(Constants.ARG_ADD_DIGEST, addDigestBean);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mAddDigestBean = (AddDigestBean) getArguments().get(Constants.ARG_ADD_DIGEST);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_digest_preview, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @Override
    protected void initUI(View view) {
        super.initUI(view);
        initData();
    }

    private void initData() {
    }

    @Override
    public void onClick(View v) {
    }

    private void reqCatalogs() {
        new RequestServerTask<CatalogListResponse>(CatalogListResponse.class) {
            @Override
            protected String requestServer() {
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("bookId", mAddDigestBean.bookId);
                return HttpUtil.post(API.GET_BOOK_MENU, params);
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
            }


            //                ////////////////Notice！！ 目前目录是一次性全部加载 所以不算分页 加载成功后直接设置已全部加载
            @Override
            protected void onSuccess(CatalogListResponse result) {
                //没有更多数据 不能加载更多
                if (result.data == null || result.data.length == 0) {
                } else {
                }
            }
        }.start();
    }
}
